package cn.tutu.blockchain.cktrecord.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.tutu.blockchain.base.Result;
import cn.tutu.blockchain.cktrecord.dao.CktRecordDao;
import cn.tutu.blockchain.cktrecord.entity.CktRecord;
import cn.tutu.blockchain.cktrecord.service.CktRecordService;
import cn.tutu.blockchain.common.Page;

@Service
@Transactional
public class CktRecordServiceImpl implements CktRecordService {

	@Autowired
	private CktRecordDao cktRecordDao;

	@Override
	public void insertBatch(List<CktRecord> cktRecordList) {
		cktRecordDao.insertBatch(cktRecordList);

	}

	@Override
	public Map<String, String> getPaymentRecord() {
		List<Result> resultes = cktRecordDao.findPayMentRecord();
		Map<String, String> map = new HashMap<String, String>();
		for (Result result : resultes) {
			map.put(result.getCode(), result.getMessage());
		}
		return map;

	}

	@Override
	public Map<String, String> getTransRecord() {
		List<Result> resultes = cktRecordDao.findTransRecord();
		Map<String, String> map = new HashMap<String, String>();
		for (Result result : resultes) {
			map.put(result.getCode(), result.getMessage());
		}
		return map;

	}

	@Override
	public PageInfo<CktRecord> getByUserId(String userId, Page page) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize());
		List<CktRecord> list = cktRecordDao.findByUserId(userId);
		PageInfo<CktRecord> pageInfo = new PageInfo<CktRecord>(list);
		return pageInfo;
	}

	@Override
	public Map<String, String> getExchangeRecord() {
		List<Result> resultes = cktRecordDao.getExchangeRecord();
		Map<String, String> map = new HashMap<String, String>();
		for (Result result : resultes) {
			map.put(result.getCode(), result.getMessage());
		}
		return map;
	}

	@Override
	public PageInfo<CktRecord> getByCktId(String cktId, Page page) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize());
		List<CktRecord> list = cktRecordDao.findByCktId(cktId);
		PageInfo<CktRecord> pageInfo = new PageInfo<CktRecord>(list);
		return pageInfo;
	}

}
